package com.xmjs.baselibrary.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * 监听APP前后台切换的广播
 */
public class AppFrontBackReceiver extends BroadcastReceiver {
    public static final String APP_BACT_TO_FRONT = "APP_BACT_TO_FRONT";
    public static final String APP_FRONT_TO_BACK = "APP_FRONT_TO_BACK";
    private OnAppStatusListener listener;

    public AppFrontBackReceiver(OnAppStatusListener listener) {
        this.listener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(APP_BACT_TO_FRONT)) {
            if (listener != null)
                listener.onFront();
        } else if (intent.getAction().equals(APP_FRONT_TO_BACK)) {
            if (listener != null)
                listener.onBack();
        }
    }

    public interface OnAppStatusListener {
        void onFront();

        void onBack();
    }
}
